<%@page import="models.RouteModel"%>
<%@page import="admin.data.GeoData"%>
<%@page import="java.util.ArrayList"%>
<%@page import="models.GeoModel"%>
<%@page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@page import="java.util.TreeMap"%>
<%@page import="helpers.UrlHelper"%>

<%
RouteModel routeModel = (RouteModel) request.getAttribute("routeModel");;
TreeMap check = (TreeMap) request.getAttribute("check");
String success = (String) request.getAttribute("success");
ArrayList<GeoModel> geos = (ArrayList<GeoModel>) request.getAttribute("geos");
GeoData geoData = new GeoData();
String parameter = "";
String city = "";
String district = "";
GeoModel currentCity;
if(city!=null&&!city.isEmpty()){
	currentCity= geoData.getGeo(city);
}else{
	currentCity = geoData.getFirstCity();
}

String[] listGeoId = routeModel.getListGeoId().split(",");
String[] listGeoName = routeModel.getListGeoName().split(",");
String wardOption = "";
for(int i=0;i<listGeoId.length;i++)
{
	wardOption += "<option value='"+listGeoId[i]+"'>"+listGeoName[i]+"</option>";
}
%>
<jsp:include page="/admin/layouts/header.jsp">
    <jsp:param name="language" value="1" />
</jsp:include>
	<script type="text/javascript" src="/admin/js/add_route.js"></script>
	<script type="text/javascript">
		jQuery(document).ready(function () {			
			loadCity("");
			loadDistrict("", "");
			loadWard("");
		});
		var server = "<%=UrlHelper.getServerUrl(request)%>";
	</script>
		<div class="maincontent noright">
        	<div class="maincontentinner">
                <ul class="maintabmenu multipletabmenu">
                	<li><a href="/admin/route/list">Quản lý tuyến</a></li>
                	<li class="current"><a href="/admin/route/add">Cấu hình tuyến</a></li>
                </ul><!--maintabmenu-->
                
                <div class="content">
					<% if (success != null) {%>
					<div class="notification msgsuccess">
                        <a class="close"></a>
                        <p><%=success %></p>
                    </div>
					<% } %>
                    <div class="contenttitle">
                    	<h2 class="form"><span>Thay đổi tuyến</span></h2>
                    </div><!--contenttitle-->
            
                    <form method="post" action="/admin/route/edit/" class="stdform stdform2" id="add_route">
                        <p>
                        	<label>Tên tuyến</label>
                            <span class="field">
                            	<input type="text" class="smallinput" name="name" id="name" value="<%=routeModel.getName()%>">
                            	<% if (check.get("name") != null) { %>
									<label for="name" generated="true" class="error"><%=check.get("name") %></label>
								<% } %>
                            </span>
                        </p>
                                                
                        <p>
                        	<label>Mô tả</label>
                            <span class="field">
                            	<input type="text" class="smallinput" name="description" id="description" value="<%=routeModel.getDescription()%>">
                            </span>
                        </p>                         
                        
                        <p>
                    		<label>Tỉnh/Thành phố</label>
                            <span class="field">
	                            <select name="city" id="city">
	                            	<%
	                            		for(GeoModel geo: geoData.getCities()){
	                            	%>
	                            	<option <%=(city!=null&&city.equals(geo.getGeoId()))?"selected":"" %> value="<%=geo.getGeoId()%>"><%=geo.getName() %></option>	                                
	                                <%
	                            		}
	                                %>	                            
	                            </select>
                            </span>                        
                    	</p>
                    	<p>
                    		<label>Quận/huyện</label>
                             <span class="field">
	                            <select name="district" id="district">
	                            	<option value="">Chọn quận/huyện</option>                            
	                            </select>
                            </span>                           
                    	</p>
                        
                        
                        <p>
                        	<label>Phường/xã</label>
                            <span class="dualselect" id="dualselect">
                            	<select size="10" multiple="multiple" name="ward"></select>
                            	
                                <span class="ds_arrow">
                                    <span class="arrow ds_next">»</span>                                
                                	<span class="arrow ds_prev">«</span>
                                </span>                                
                                
                                <select size="10" multiple="multiple" name="ward2" id="ward2"></select>
                            </span>
                        </p>
                        
                        <input type="hidden" class="smallinput" name="geoName" id="geoName">
                        <input type="hidden" class="smallinput" name="geoId" id="geoId">    
                        <input type="hidden" class="smallinput" name="routeId" id="routeId" value="<%=routeModel.getId() %>">    
                                            
                        <p class="stdformbutton">
                        	<button class="submit radius2" id="submit-button">Submit Button</button>
                            <input type="reset" value="Reset Button" class="reset radius2" id="reset-button">
                        </p>
                        
                    </form>
                    
                    <br clear="all">
                    
                </div><!--content-->
                
            </div><!--maincontentinner-->
            
            <jsp:include page="/admin/elements/copyright.jsp">
            	<jsp:param name="language" value="1" />
			</jsp:include>
            
        </div>
<script type="text/javascript">
jQuery(document).ready(function () {	
	jQuery('#ward2').html("<%=wardOption%>");
});
</script>
<jsp:include page="/admin/layouts/footer.jsp">
    <jsp:param name="language" value="1" />
</jsp:include>